// 详情页
app.register.controller('detailCtrl',['$scope','$location', '$http','$stateParams','$timeout','$cookies',
    function ($scope,$location,$http,$stateParams,$timeout,$cookies) {
    //请求详情数据
    $http.get($config.host+'/index.php?s=/Zmhhr/detailByID&id='+$stateParams.uid).success(function(json) {
        if(json.success){
            // 报名成功
            $scope.users = json.data[0];
            //设置分享名字
            $cookies.hhrname = $scope.users.name;
            $scope.wxshare(true,$scope.users.type);

            if($scope.users.type=='1'){
                $scope.title = 'create';
            }else if($scope.users.type=='2'){
                $scope.title = 'youth';
            }
        }
    });

    $scope.getPoster = function(){
        $scope.showPrompt('正在生成，请稍后');
        $http.get($config.host+'/index.php?s=/Zmhhr/poster&id='+$stateParams.uid).success(function(json) {
            if(json.success){
                // 报名成功
                console.log(encodeURIComponent(json.data.img));
                $location.path('/poster/'+$scope.users.type+'/'+encodeURIComponent(json.data.img));
            }else{
                $scope.showPrompt(json.msg);
            }
        });
    }

    $scope.clickVoteOption = function (value) {
        return function () {
            function loading() {
                $('.votebox i').show().addClass('fadeOutUp')
                $timeout(function () {
                    $('.votebox i').removeClass('fadeOutUp').hide();
                },1000);
                $scope.users.vote++;
            }
            if(value=='bottom'){
                $config.toTop(loading);
            }else{
                loading();
            }
        }
    }
}])

app.register.controller('redetailCtrl',['$scope','$location', '$http','$stateParams','$timeout','$cookies',
    function ($scope,$location,$http,$stateParams,$timeout,$cookies) {
        //请求详情数据
        $http.get($config.host+'/index.php?s=/Zmhhr/detailByID&id='+$stateParams.uid+'/&i=2').success(function(json) {
            if(json.success){
                // 报名成功
                $scope.users = json.data[0];
                //设置分享名字
                $cookies.hhrname = $scope.users.name;
                $scope.wxshare(true,$scope.users.type);

                if($scope.users.type=='1'){
                    $scope.title = 'create';
                }else if($scope.users.type=='2'){
                    $scope.title = 'youth';
                }
            }
        });

        $scope.getPoster = function(){
            $scope.showPrompt('正在生成，请稍后');
            $http.get($config.host+'/index.php?s=/Zmhhr/poster&id='+$stateParams.uid+'/&i=2').success(function(json) {
                if(json.success){
                    // 报名成功
                    console.log(encodeURIComponent(json.data.img));
                    $location.path('/poster/'+$scope.users.type+'/'+encodeURIComponent(json.data.img));
                }else{
                    $scope.showPrompt(json.msg);
                }
            });
        }

        $scope.clickVoteOption = function (value) {
            return function () {
                function loading() {
                    $('.votebox i').show().addClass('fadeOutUp')
                    $timeout(function () {
                        $('.votebox i').removeClass('fadeOutUp').hide();
                    },1000);
                    $scope.users.vote++;
                }
                if(value=='bottom'){
                    $config.toTop(loading);
                }else{
                    loading();
                }
            }
        }
    }])